<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %> 
<!DOCTYPE html>
<html>
<head>
	<title>未添加药品</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>未添加药品</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="toList.html">采购项目</a></li>
            <li class="active"><a href="#">未添加药品</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    
	                <div class="input">
	                    <div class="textalign1">通用名：</div>
                        <div class="boxinput">
                            <input type="text" class="textinput" id="sdrugName" name="sdrugName" placeholder="通用名" />
                        </div>
	                    
	                    <!-- <div class="textalign1">药品编码：</div>
	                    <div class="boxinput">
	                        <input type="text" class="textinput" id="sdrugCode" name="sdrugCode" placeholder="药品编码" />
	                    </div> -->

	                   <div class="textalign">生产企业：</div>
	                    <div class="boxinput">
	                        <input type="text" class="textinput" id="sdrugComp" name="sdrugComp" placeholder="生产企业" />
	                    </div> 
	                    <div class="textalign" >
	                        <button  id="selectSerch"    type="button" onclick="search();" class="btn btn-success btn-sm"> <spring:message code="message.button.seachSpacing"/> </button>
	                    </div>
	               </div>
	               
	                <%-- <div class="input">
	                    <div class="textalign1">是否基药：</div>
	                    <div class="boxinput">
	                        <select id="sbaseDrug" name="status" class="textinput">
	                            <option  value="">请选择</option>
	                            <option  value="1">是</option>
	                            <option value="0">否</option>
	                        </select>
	                    </div>
	                    
	                    
	               </div> --%>
                    
                    
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
	        <a href="javascript:batchSubmitDrugTOProj();" class="btn btn-default btn-sm">添 加</a>
	         <a href="javascript:checkAddDrug();" class="btn btn-default btn-sm" >已添加药品</a>
	         
	         <a href="${ctx}/bidProject/toImportFileList.html?projId=${projId}" class="btn btn-default btn-sm" >批量导入管理</a>
	         <a href="toPurList.html" class="btn btn-default btn-sm" >返 回</a>
        </div>
        <form action="${ctx}/bidProject/toAddedBidPurProjectDrugsList.html" method="post" id="addDurgFrom">
        <input type="hidden" name="projId" id="projId">
        <input type="hidden" name="projName" id="projName">
        </form>
        
        <!-- 批量导入 -->
            <div class="modal fade" id="batchImport" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">导&nbsp;入</h5>
                    </div>
                    
                    
                    <div class="modal-body">
                    <div class="form-group form-group-xs">
								<label for="recipient-name" class=" control-label">模板下载：</label>
								<div class="">
								<a href="${ctx }/bidProject/downloadModel.html">分类采购药品导入模板</a>
								</div>
							</div>
                    
                        <form name="importform" id="importform" method="post" action="${ctx }/bidProject/bathImportView.html?projId=${projId}" enctype="multipart/form-data">
                        <input type="hidden" name="projId" id="projId" value="${projId}" />
                            <div class="form-group form-group-xs">
                                <label for="recipient-name" class="control-label">导入文件:</label>
                                <input type="file" name="drugFile" id="drugFile"/>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="bathImport();" class="btn btn-primary btn-sm">导 入</button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">关 闭</button>
                        
                    </div>
                </div>
            </div>
        </div>
        
        
        
        
        
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">

    function importFile(){
    	$('#batchImport').modal({
            keyboard: true
        });
    }
    function bathImport(){
		var fileName = $.trim($("#drugFile").val());
		if (fileName == ""){
			$.HN.message.alert("请选择导入文件！", "消息", "warn");
			return;
		}
		$("#importform").submit();
	}
    $('#importform').ajaxForm({ 
	    dataType: 'json', 
    	success: function(returnData) {
    	if(returnData.success) {
    		$.HN.message.alert('上传成功！', '提示信息', 'success');
    		$('#batchImport').modal('hide');
		}else{
			$.HN.message.alert('添加失败，请重新添加！', '提示信息', 'success');
    	}
       } 	
   });
	function search() {
		var sdrugCode =  $.trim($("#sdrugCode").val());
		var sdrugName = $.trim($("#sdrugName").val());
		var sdrugComp = $.trim($("#sdrugComp").val());
		var sbaseDrug = $("#sbaseDrug").val();
		var slowDrug = $("#slowDrug").val();
		$("#gridlist").jqGrid("clearGridData");
			$("#gridlist").jqGrid('setGridParam',{  
			url:"${ctx}/bidProject/getUnBidPurProjectDrugListJson.html",
			mtype: "POST",
	        datatype:'json',
	        postData:{"sdrugCode":sdrugCode, "sdrugName":sdrugName, "sdrugComp":sdrugComp, "sbaseDrug":sbaseDrug, "slowDrug":slowDrug},
	        page : 1
	    }).trigger("reloadGrid"); //重新载入  
	}
        $(function () {
        	
            //加载页面光标在名字框内，位于第一个
            $("#sdrugName").focus();
        
            //绑定回车    id="selectSerch"  
            $('#sdrugName,#sdrugCode,#sdrugComp,#sbaseDrug').bind('keydown', function(event) {
                if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
                        $('#selectSerch').click();
                    }
             }); 
            
        	
            $("#gridlist").jqGrid({
                url: "getUnBidPurProjectDrugListJson.html",
                mtype: "POST",
                postData: { "projId" : "${bidProject.projId}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
                           
                           '药品编码',
                           'compCode',
                           '通用名', 
                           '剂型', 
                           '规格',
                           '转换系数',
                           '单位',
                           '材质', 
                           '生产企业',
                           '基药'
                           ],
                colModel: [
					
                    { name: 'drugCode', width: 60,hidden:true , align:"center",sortable: false,
						formatter:function(val, opts, row) {
                            return "<a href=\"javascript:showDrugInfo('"+val+"')\">"+val+"</a>"
                           }
                    },
                    { name: 'compCode', width: 120 ,hidden:true, align:"center" ,sortable: false},
                    { name: 'drugName', width: 100 , align:"center" ,sortable: false},
                    { name: 'formName', width: 40 , align:"center" ,sortable: false},
                    { name: 'specName', width: 60 , align:"center" ,sortable: false},
                    { name: 'factor', width: 40 , align:"center" ,sortable: false},
                    { name: 'unit', width: 40 , align:"center" ,sortable: false},
                    { name: 'materialName', width: 40,hidden:true , align:"center" ,sortable: false},
                    {name : 'compName',width :80,align : "center"/* ,
                    	 formatter:function(val, opts,row) {
                             return "<a href='javascript:showCompInfo(\"" + row.compCode + "\", \"" + val + "\");'>"+val+"</a>"
                        } */
					},
                    { name: 'drugAttr', width: 100 ,hidden:true, align:"center" ,sortable: false,
						formatter:function(cellvalue, options, row){
							if(cellvalue==1){
								return "国家基药（2012）";
								}else if(cellvalue==2){ 
									return "省增补"; 
									}else if(cellvalue==3){
										return "其它"; 
										}else{
											return "非基药";
											}
							}
					}
                    
                ],
                
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${bidProject.name}-未添加药品",
              //序号宽度自动变化
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false,
                    id: "drugCode"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
			$("#gridlist").jqGrid("setGridHeight", create());

        });


        function batchSubmitDrugTOProj(){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];

    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的药品！", "消息", "warn");
    			return;
    		}
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
				list.push({"drugCode":rowId,"projId":'${bidProject.projId}',"compCode":rowdata.compCode});
    		}
    		submitDrugTOProj(JSON.stringify(list));
        }
        
        
        
    	function submitDrugTOProj(list){
           	$.ajax({
				type:"POST",
				url:"batchSubmitDrugTOProj.html",
				data:{"drugs":list},
				dataType:"json",
				success:function(returnData){
					if (returnData.success == true) {
						$("#gridlist").jqGrid("clearGridData");
	    				$("#gridlist").jqGrid().trigger("reloadGrid");
	    				$.HN.message.alert("添加药品成功！", "消息", "success");
	    			} else {
	    				$.HN.message.alert("添加药品失败！", "消息", "error");
	    			}
				}
			});
        	
        }
        
    	function checkAddDrug(){
    		$("#projId").val("${bidProject.projId}");
    		$("#projName").val("${bidProject.name}");
    		$("#addDurgFrom").submit();
    	}
    </script>
</body>
</html>